package inventory.generator;

import com.baomidou.mybatisplus.enums.IdType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.DbType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;

/**
 * @author sxt
 * @create 2019-11-06 16:47
 */
public class MapperGenerator {
    public static void main(String[] args) {

        //全局配置
        GlobalConfig config = new GlobalConfig();
        config.setActiveRecord(true)
                .setAuthor("sxt")
                .setOutputDir("D:\\ProcessingProjects\\inventory\\inventory\\src\\main\\java")
                .setFileOverride(true)
                .setEnableCache(false)
                .setXmlName("%sMapper")
                .setMapperName("%sMapper")
                .setServiceName("%sService")
                .setServiceImplName("%sServiceImpl")
                .setControllerName("%sController")
                .setBaseResultMap(true)// XML ResultMap
                .setIdType(IdType.UUID);

        //数据源配置
        DataSourceConfig dataSourceConfig = new DataSourceConfig();
        dataSourceConfig.setDbType(DbType.MYSQL)
                .setUrl("jdbc:mysql://47.98.244.28:3306/inventory?useUnicode=true&characterEncoding=utf8")
                .setDriverName("com.mysql.jdbc.Driver")
                .setUsername("root")
                .setPassword("sxt294416");

        //策略配置
        StrategyConfig strategyConfig = new StrategyConfig();
        strategyConfig.setCapitalMode(false)
                .setDbColumnUnderline(true)
                .setNaming(NamingStrategy.underline_to_camel)
                .setInclude(new String[] {
//                        "equipment",
//                        "in_repository_record",
//                        "manager",
//                        "material_category",
//                        "material_stuff",
//                        "material_typical",
//                        "notice",
//                        "permission_list",
//                        "permission_record",
//                        "reparation_record",
//                        "repository",
//                        "role",
//                        "sale_request",
//                        "terminal",
//                        "user_repository_relationship",
                        "manager_permission_record"

                });


        //包名策略
        PackageConfig packageConfig = new PackageConfig();
        packageConfig.setParent("inventory")
                .setController("controller")
                .setEntity("entity")
                .setService("service")
                .setServiceImpl("service.impl")
                .setMapper("mappers")
                .setXml("mappers");


        //集成配置
        AutoGenerator autoGenerator = new AutoGenerator();
        autoGenerator.setGlobalConfig(config)
        .setDataSource(dataSourceConfig)
        .setStrategy(strategyConfig)
        .setPackageInfo(packageConfig);

        autoGenerator.execute();




    }
}
